var health=health||{};
var role;


health.Health=function(){
	var s = this;
    health.container = s;
	F2xContainer.call(s);
	if(window){
		window.Health = this;
	}


};
F2xExtend(health.Health,F2xContainer);
health.Health.prototype.initUI=function(){
	var s = this;
	//f2x_auto_created_init_start
	var _d0=Flash2x.b("health","bg");
	Flash2x.d(_d0,{x:-11,y:-13,a:0.4663,b:0.4663});
	s.addChild(_d0);
	//f2x_auto_created_init_end
	
};


(function(global){
   var $api = global.$api || {};



    function createRole(type, position){
        var type = type || 'man';
        var position = position || {x:0, y:0};
        var positionX = position.x || 0;
        var positionY = position.y || 0;

        var role = null;
        var container = health.container;

        if(positionX > 0 && positionX < 1){
            positionX = positionX * container.stage.divWidth;
        }

        if(positionY > 0 && positionY < 1){
            positionY = positionY * container.stage.divHeight;
        }



        switch(type){
            case 'man':
                role =  new health.Man();
                role.x = positionX;
                role.y = positionY;
                break;
            case 'woman':
                role =  new health.Woman();
                role.x = positionX;
                role.y = positionY;
                break;
            case 'ruler':
                role = new health.Ruler();
                role.x = positionX;
                role.y = positionY;
                break;
            default:
                trace('empty is created!');
                return null;
        }

        if(role){
            container.addChild(role);
        }

        if(role instanceof annie.MovieClip){
            role.__proto__.start = startCheck;
        }else{
            role.__proto__.start = setValue;
        }


        return role;
    }

    var IS_PLAYING = false;
    var interval;
    function startCheck(time){
        var time = time || 3000;
        this.dispatchEvent('start');
        var self = this;

        if(!interval){
            this.nextFrame();
            this.dot.play();
        }

        interval = setInterval(function(){
            self.nextFrame();
            IS_PLAYING = true;
            if(self.currentFrame == self.totalFrames){
                self.dot.stop();
                clearInterval(interval);
                self.gotoAndStop(1);
                self.dispatchEvent('complete');
                IS_PLAYING = false;
            }

        },time);
    }

    function setValue(value){
        this.dispatchEvent('start');
        //this.height = (value -25)/(45-25) * this.height;
        this.line.scaleY = (value -25)/(45-25);
        trace('start take temperature');
    }



    $api.create = createRole;

    if(!global.$api){
        global.$api = $api;
    }
    //trace(global.$api);
    return global;

})(window);





